<?php
include('Publication.php');
include('Author.php');

if(isset($_GET['firstID'])) {
    $firstID = $_GET['firstID'];
    $secondID = $_GET['secondID'];
    $domainID = $_GET['domainID'];
    $subDomainID = $_GET['subDomainID'];
ini_set('max_execution_time', 300);

$count = array();
$count2 = array();

$results = array();
$results2 = array();

for ($i=2000; $i<2011; $i++)
{
    $pub = new Publication;
    $author = new Author;
    $pub2 = new Publication;
    $author2 = new Author;

    $pub->orgID = $firstID;
    $author->orgID = $firstID; 
    
    $pub2->orgID = $secondID;
    $author2->orgID = $secondID; 
   
    $pub->domainID = $domainID;
    $author->domainID = $domainID;
    
    $pub2->domainID = $domainID;
    $author2->domainID = $domainID;
    
    if ($subDomainID !=0) 
    {
        $pub->subDomainID = $subDomainID;
        $author->subDomainID = $subDomainID;
    
        $pub2->subDomainID = $subDomainID;
        $author2->subDomainID = $subDomainID;
    }
    
    $pub->yearStart=$i;
    $pub->yearEnd=$i;
    
    $pub2->yearStart=$i;
    $pub2->yearEnd=$i;
    
    $author->yearStart=$i;
    $author->yearEnd=$i;
    
    $author2->yearStart=$i;
    $author2->yearEnd=$i;

    $pub->getPublications();
    $author->getAuthors();

    $pub2->getPublications();
    $author2->getAuthors();
    
    $numAuthors = intval($author->getAuthorCount());
    $numAuthors2 = intval($author2->getAuthorCount());  
    
    if ($numAuthors == 0) 
    {
        $numAuthors = 1;
    }
    
    if ($numAuthors2 == 0) 
    {
        $numAuthors2 = 1;
    }
    $normalized = intval($pub->getPublicationCount())/$numAuthors;
    $normalized2 = intval($pub2->getPublicationCount())/$numAuthors2;
    
    array_push($count, $pub->getPublicationCount());
    array_push($count2, $pub2->getPublicationCount());
    
    array_push($results,$normalized);
    array_push($results2,$normalized2);
    
    
}

$jsonObj = '{"firstSchoolNorm":' . json_encode($results) . ',"secondSchoolNorm":' . json_encode($results2) . ",";
$jsonObj .= '"firstSchool":' . json_encode($count) . ',"secondSchool":' . json_encode($count2) . "}";
echo $jsonObj;
}

?>